package com.generator.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.generator.dao.SysUserDao;
import com.generator.entity.UserDetail;
import com.generator.entity.UserEntity;
import com.generator.service.SysUserDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @version 1.0
 * @Author Xing
 * @Date 2023/12/3 22:14
 */
@Service
public class SysUserDetailServiceImpl implements SysUserDetailService {
    @Autowired
    private SysUserDao userDao;
    @Override
    public UserDetail getUserDetailById(Long id) throws Exception {
        UserEntity sysUserEntity = userDao.selectById(id);
        UserDetail userDetail = new UserDetail();
        userDetail.setUserEntity(sysUserEntity);
        initUserData(userDetail);
        return userDetail;
    }

    @Override
    public UserDetail getUserDetailByUsername(String username) throws Exception {
        System.out.println(1);
        QueryWrapper<UserEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("username", username);
        System.out.println(2);
        UserEntity sysUserEntity = userDao.selectOne(wrapper);
        UserDetail userDetail = new UserDetail();
        if (sysUserEntity ==null){
            return userDetail;
        }
        userDetail.setUserEntity(sysUserEntity);
//        initUserData(userDetail);
        return userDetail;
    }

    /**
     * 初始化用户数据
     */
    private void initUserData(UserDetail userDetail) {
        if (userDetail == null) {
            return;
        }
    }
}
